/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SuppliesFrame.java
 *
 * Created on Mar 10, 2011, 4:58:49 PM
 */

package gbbmgmt;

import org.jdesktop.application.Action;
import java.util.*;
import javax.swing.JOptionPane;

/**
 *
 * @author dchapman
 */
public class SuppliesFrame extends javax.swing.JFrame {

    public ArrayList<String[]> Items;
    public ArrayList<String[]> Vendor;
    public ArrayList<String[]> Wearhouse;

    /** Creates new form SuppliesFrame */
    public SuppliesFrame() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jComboBox1 = new javax.swing.JComboBox();
        jComboBoxItems = new javax.swing.JComboBox();
        jButtonCustFirst = new javax.swing.JButton();
        jButtonCustPrev = new javax.swing.JButton();
        jButtonCustNext = new javax.swing.JButton();
        jButtonCustLast = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabelID = new javax.swing.JLabel();
        jTextFieldItemName = new javax.swing.JTextField();
        jComboBoxVendor = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldPrice = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTextFieldQty = new javax.swing.JTextField();
        jTextFieldUnit = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        jLabel7 = new javax.swing.JLabel();
        jTextFieldItemNum = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabelQty = new javax.swing.JLabel();
        jLabelUnits = new javax.swing.JLabel();
        jSeparator3 = new javax.swing.JSeparator();
        jButtonUpdate = new javax.swing.JButton();
        jButtonNew = new javax.swing.JButton();
        jButtonSubmit = new javax.swing.JButton();
        jButtonExit = new javax.swing.JButton();
        jLabelscode = new javax.swing.JLabel();
        jLabelStockCode = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jComboBoxWearhouse = new javax.swing.JComboBox();

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBox1.setName("jComboBox1"); // NOI18N

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        jComboBoxItems.setName("jComboBoxItems"); // NOI18N
        jComboBoxItems.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
                jComboBoxItemsPopupMenuWillBecomeInvisible(evt);
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
            }
        });

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(gbbmgmt.GBBMGMTApp.class).getContext().getActionMap(SuppliesFrame.class, this);
        jButtonCustFirst.setAction(actionMap.get("FirstRecord")); // NOI18N
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(gbbmgmt.GBBMGMTApp.class).getContext().getResourceMap(SuppliesFrame.class);
        jButtonCustFirst.setText(resourceMap.getString("jButtonCustFirst.text")); // NOI18N
        jButtonCustFirst.setName("jButtonCustFirst"); // NOI18N

        jButtonCustPrev.setAction(actionMap.get("PrevRecord")); // NOI18N
        jButtonCustPrev.setText(resourceMap.getString("jButtonCustPrev.text")); // NOI18N
        jButtonCustPrev.setName("jButtonCustPrev"); // NOI18N

        jButtonCustNext.setAction(actionMap.get("NextRecord")); // NOI18N
        jButtonCustNext.setText(resourceMap.getString("jButtonCustNext.text")); // NOI18N
        jButtonCustNext.setName("jButtonCustNext"); // NOI18N

        jButtonCustLast.setAction(actionMap.get("LastRecord")); // NOI18N
        jButtonCustLast.setText(resourceMap.getString("jButtonCustLast.text")); // NOI18N
        jButtonCustLast.setName("jButtonCustLast"); // NOI18N

        jSeparator1.setName("jSeparator1"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabelID.setText(resourceMap.getString("jLabelID.text")); // NOI18N
        jLabelID.setName("jLabelID"); // NOI18N

        jTextFieldItemName.setText(resourceMap.getString("jTextFieldItemName.text")); // NOI18N
        jTextFieldItemName.setName("jTextFieldItemName"); // NOI18N

        jComboBoxVendor.setName("jComboBoxVendor"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jTextFieldPrice.setText(resourceMap.getString("jTextFieldPrice.text")); // NOI18N
        jTextFieldPrice.setName("jTextFieldPrice"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jTextFieldQty.setText(resourceMap.getString("jTextFieldQty.text")); // NOI18N
        jTextFieldQty.setName("jTextFieldQty"); // NOI18N

        jTextFieldUnit.setName("jTextFieldUnit"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jSeparator2.setName("jSeparator2"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jTextFieldItemNum.setText(resourceMap.getString("jTextFieldItemNum.text")); // NOI18N
        jTextFieldItemNum.setName("jTextFieldItemNum"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jLabelQty.setText(resourceMap.getString("jLabelQty.text")); // NOI18N
        jLabelQty.setName("jLabelQty"); // NOI18N

        jLabelUnits.setText(resourceMap.getString("jLabelUnits.text")); // NOI18N
        jLabelUnits.setName("jLabelUnits"); // NOI18N

        jSeparator3.setName("jSeparator3"); // NOI18N

        jButtonUpdate.setAction(actionMap.get("UpdateSup")); // NOI18N
        jButtonUpdate.setText(resourceMap.getString("jButtonUpdate.text")); // NOI18N
        jButtonUpdate.setName("jButtonUpdate"); // NOI18N

        jButtonNew.setAction(actionMap.get("NewSup")); // NOI18N
        jButtonNew.setText(resourceMap.getString("jButtonNew.text")); // NOI18N
        jButtonNew.setName("jButtonNew"); // NOI18N

        jButtonSubmit.setAction(actionMap.get("SubmitSup")); // NOI18N
        jButtonSubmit.setText(resourceMap.getString("jButtonSubmit.text")); // NOI18N
        jButtonSubmit.setName("jButtonSubmit"); // NOI18N

        jButtonExit.setAction(actionMap.get("ExitSup")); // NOI18N
        jButtonExit.setText(resourceMap.getString("jButtonExit.text")); // NOI18N
        jButtonExit.setName("jButtonExit"); // NOI18N

        jLabelscode.setText(resourceMap.getString("jLabelscode.text")); // NOI18N
        jLabelscode.setName("jLabelscode"); // NOI18N

        jLabelStockCode.setText(resourceMap.getString("jLabelStockCode.text")); // NOI18N
        jLabelStockCode.setName("jLabelStockCode"); // NOI18N

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jComboBoxWearhouse.setName("jComboBoxWearhouse"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jComboBoxItems, 0, 276, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonCustFirst)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonCustPrev)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonCustNext)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonCustLast)
                .addContainerGap())
            .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel9)
                    .addComponent(jLabel5)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabelID)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 290, Short.MAX_VALUE)
                        .addComponent(jLabelscode)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabelStockCode))
                    .addComponent(jTextFieldItemName, javax.swing.GroupLayout.DEFAULT_SIZE, 408, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jComboBoxVendor, 0, 271, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldPrice, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jTextFieldQty, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldUnit, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldItemNum, javax.swing.GroupLayout.DEFAULT_SIZE, 184, Short.MAX_VALUE))
                    .addComponent(jComboBoxWearhouse, 0, 408, Short.MAX_VALUE))
                .addContainerGap())
            .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelQty)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelUnits)
                .addContainerGap(385, Short.MAX_VALUE))
            .addComponent(jSeparator3, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButtonUpdate)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonNew)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonSubmit)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 156, Short.MAX_VALUE)
                .addComponent(jButtonExit)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jComboBoxItems, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonCustFirst)
                    .addComponent(jButtonCustPrev)
                    .addComponent(jButtonCustNext)
                    .addComponent(jButtonCustLast))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabelID)
                    .addComponent(jLabelStockCode)
                    .addComponent(jLabelscode))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextFieldItemName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jComboBoxVendor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jTextFieldQty, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(jTextFieldUnit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(jTextFieldItemNum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jComboBoxWearhouse, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jLabelQty)
                    .addComponent(jLabelUnits))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonUpdate)
                    .addComponent(jButtonNew)
                    .addComponent(jButtonSubmit)
                    .addComponent(jButtonExit))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBoxItemsPopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_jComboBoxItemsPopupMenuWillBecomeInvisible
        // TODO add your handling code here:
        String Itm = jComboBoxItems.getSelectedItem().toString();

        for(String s[] : Items){
            if (s[1].equals(Itm)) {
                DBA.openDBCon();
                DBA.GetSuppliesData(s[0]);
                DBA.closeDBCon();
            }
        }

        SetData();
}//GEN-LAST:event_jComboBoxItemsPopupMenuWillBecomeInvisible

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new SuppliesFrame().setVisible(true);
            }
        });
    }

    public void LoadList(){
        //Remove all vendors in list.
        jComboBoxItems.removeAllItems();
        jComboBoxVendor.removeAllItems();

        DBA.openDBCon();
        Items = DBA.RunSQLQuery("SELECT SupID,SupName FROM Supplies");
        Vendor = DBA.RunSQLQuery("SELECT VID,VName From Vendors");
        Wearhouse = DBA.RunSQLQuery("SELECT WearhouseID,WHDesc From Wearhouse WHERE WearhouseID > '130'");
        DBA.closeDBCon();

        for(String s[] : Items){
            jComboBoxItems.addItem(s[1]);
        }

        for(String s[] : Vendor){
            jComboBoxVendor.addItem(s[1]);
        }

        for(String s[] : Wearhouse){
            jComboBoxWearhouse.addItem(s[1]);
        }

        //Hide submit button.
        jButtonSubmit.setVisible(false);

        LastRecord();
    }

    @Action
    public void LastRecord() {
        jComboBoxItems.setSelectedIndex(jComboBoxItems.getItemCount()-1);

        String Itm = jComboBoxItems.getSelectedItem().toString();

        for(String s[] : Items){
            if (s[1].equals(Itm)) {
                DBA.openDBCon();
                DBA.GetSuppliesData(s[0]);
                DBA.closeDBCon();
            }
        }

        SetData();
    }

    public void SetData(){
        jLabelID.setText(Integer.toString(DBA.SupID));
        jTextFieldItemName.setText(DBA.SupName);
        jTextFieldItemNum.setText(DBA.SupNumber);
        jTextFieldPrice.setText(Float.toString(DBA.SupPrice));
        jTextFieldQty.setText(Float.toString(DBA.SupQtyPer));
        jTextFieldUnit.setText(DBA.SupUnits);
        jLabelQty.setText(Float.toString(DBA.SupOnHand));
        jLabelUnits.setText(DBA.SupUnits);

        String whcode = "0";
        
        for(String s[] : Wearhouse){
            if (s[0].equals(Integer.toString(DBA.SupWH))) {
                jComboBoxWearhouse.setSelectedItem(s[1]);
                whcode = s[0];
            }
        }

        DBA.openDBCon();
        String scode = DBA.ReturnStockCode(whcode, jLabelID.getText());
        String StockNumber = String.format("%05d", Integer.parseInt(scode));
        DBA.GetStockCodeData(scode);
        DBA.closeDBCon();

        for(String s[] : Vendor){
            if (s[0].equals(Integer.toString(DBA.StockVendID))) {
                jComboBoxVendor.setSelectedItem(s[1]);
            }
        }
        
        jLabelStockCode.setText(StockNumber);
    }

    @Action
    public void ExitSup() {
        dispose();
    }

    @Action
    public void NewSup() {
        //Show Submit button.
        jButtonSubmit.setVisible(true);

        //Hide all appropriate buttons.
        jButtonUpdate.setVisible(false);
        jButtonNew.setVisible(false);
        jButtonCustFirst.setVisible(false);
        jButtonCustLast.setVisible(false);
        jButtonCustNext.setVisible(false);
        jButtonCustPrev.setVisible(false);
        jComboBoxItems.setVisible(false);
        jLabelID.setVisible(false);
        jLabel1.setVisible(false);
        jLabelStockCode.setVisible(false);
        jLabelscode.setVisible(false);

        //Set text in all fields to blank.
        jTextFieldItemName.setText("");
        jTextFieldItemNum.setText("");
        jTextFieldPrice.setText("");
        jTextFieldQty.setText("");
        jTextFieldUnit.setText("");

        jLabelQty.setText("0");
        jLabelUnits.setText("(Units)");

    }

    @Action
    public void SubmitSup() {
        int response = JOptionPane.showConfirmDialog(null,
                "Warning, this item will be added to the database, continue?",
                "Warning",JOptionPane.WARNING_MESSAGE);
        if (response == 0){

            String vend = jComboBoxVendor.getSelectedItem().toString();
            String VID = "0";

            for(String s[] : Vendor){
                if (s[1].equals(vend)) {
                    VID = s[0];
                }
            }

            String whcode = "0";

            for(String s[] : Wearhouse){
                String cmp = jComboBoxWearhouse.getSelectedItem().toString();
                if (s[1].equals(cmp)) {
                    whcode = s[0];
                }
            }

            String fields = "SupName,SupWH,SupPrice,SupQtyPer,SupUnits,SupNumber";
            String query = "'" +
                jTextFieldItemName.getText() + "','" +
                whcode + "','" +
                jTextFieldPrice.getText() + "','" +
                jTextFieldQty.getText() + "','" +
                jTextFieldUnit.getText() + "','" +
                jTextFieldItemNum.getText() + "'";
            DBA.openDBCon();
            DBA.RunSQLInsertQuery("Supplies",fields,query);
            //String MaID = DBA.GetLastIndex("Supplies", "SupID");
            String MaID = Integer.toString(Global.lastInsertID);
            DBA.closeDBCon();

            DBA.openDBCon();
            fields = "TableID,WHID,StockVendID";
            query = "'" + MaID + "','" + whcode + "','" + VID + "'";
            DBA.RunSQLInsertQuery("StockCode",fields,query);
            DBA.closeDBCon();
        }

        //Show Submit button.
        jButtonSubmit.setVisible(false);

        //Hide all appropriate buttons.
        jButtonUpdate.setVisible(true);
        jButtonNew.setVisible(true);
        jButtonCustFirst.setVisible(true);
        jButtonCustLast.setVisible(true);
        jButtonCustNext.setVisible(true);
        jButtonCustPrev.setVisible(true);
        jComboBoxItems.setVisible(true);
        jLabelID.setVisible(true);
        jLabel1.setVisible(true);
        jLabelStockCode.setVisible(true);
        jLabelscode.setVisible(true);

        LoadList();
    }

    @Action
    public void UpdateSup() {
        int response = JOptionPane.showConfirmDialog(null,
                "This will modify item data, continue?",
                "Warning",JOptionPane.WARNING_MESSAGE);

        if (response == 0){
            DBA.openDBCon();

            String vend = jComboBoxVendor.getSelectedItem().toString();
            String VID = "0";

            for(String s[] : Vendor){
                if (s[1].equals(vend)) {
                    VID = s[0];
                }
            }

            String SupID = jLabelID.getText();

            String whcode = "0";

            for(String s[] : Wearhouse){
                String cmp = jComboBoxWearhouse.getSelectedItem().toString();
                if (s[1].equals(cmp)) {
                    whcode = s[0];
                }
            }

            String query = "UPDATE Supplies SET SupName='" +
                        jTextFieldItemName.getText() + "',SupPrice='" +
                        jTextFieldPrice.getText() + "',SupQtyPer='" +
                        jTextFieldQty.getText() + "',SupUnits='" +
                        jTextFieldUnit.getText() + "',SupNumber='" +
                        jTextFieldItemNum.getText() + "',SupWH='" +
                        whcode + "' WHERE SupID = '" + SupID + "'";
            DBA.RunSQLUpdateQuery(query);

            int StID = Integer.parseInt(jLabelStockCode.getText());

            query = "UPDATE StockCode SET StockVendID='" +
                    VID + "',WHID='" + whcode +
                    "' WHERE StockID = '" + Integer.toString(StID) + "'";
            DBA.RunSQLUpdateQuery(query);

            DBA.closeDBCon();
        }
    }

    @Action
    public void FirstRecord() {
        jComboBoxItems.setSelectedIndex(0);

        String Itm = jComboBoxItems.getSelectedItem().toString();

        for(String s[] : Items){
            if (s[1].equals(Itm)) {
                DBA.openDBCon();
                DBA.GetSuppliesData(s[0]);
                DBA.closeDBCon();
            }
        }

        SetData();
    }

    @Action
    public void PrevRecord() {
        if(jComboBoxItems.getSelectedIndex()>=1){
            jComboBoxItems.setSelectedIndex(jComboBoxItems.getSelectedIndex()-1);
        }
        String Itm = jComboBoxItems.getSelectedItem().toString();

        for(String s[] : Items){
            if (s[1].equals(Itm)) {
                DBA.openDBCon();
                DBA.GetSuppliesData(s[0]);
                DBA.closeDBCon();
            }
        }

        SetData();
    }

    @Action
    public void NextRecord() {
        if(jComboBoxItems.getSelectedIndex() <= (jComboBoxItems.getItemCount()-2)){
            jComboBoxItems.setSelectedIndex(jComboBoxItems.getSelectedIndex()+1);
        }
        String Itm = jComboBoxItems.getSelectedItem().toString();

        for(String s[] : Items){
            if (s[1].equals(Itm)) {
                DBA.openDBCon();
                DBA.GetSuppliesData(s[0]);
                DBA.closeDBCon();
            }
        }

        SetData();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCustFirst;
    private javax.swing.JButton jButtonCustLast;
    private javax.swing.JButton jButtonCustNext;
    private javax.swing.JButton jButtonCustPrev;
    private javax.swing.JButton jButtonExit;
    private javax.swing.JButton jButtonNew;
    private javax.swing.JButton jButtonSubmit;
    private javax.swing.JButton jButtonUpdate;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBoxItems;
    private javax.swing.JComboBox jComboBoxVendor;
    private javax.swing.JComboBox jComboBoxWearhouse;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jLabelID;
    private javax.swing.JLabel jLabelQty;
    private javax.swing.JLabel jLabelStockCode;
    private javax.swing.JLabel jLabelUnits;
    private javax.swing.JLabel jLabelscode;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JTextField jTextFieldItemName;
    private javax.swing.JTextField jTextFieldItemNum;
    private javax.swing.JTextField jTextFieldPrice;
    private javax.swing.JTextField jTextFieldQty;
    private javax.swing.JTextField jTextFieldUnit;
    // End of variables declaration//GEN-END:variables

}
